package com.vogue.supplymall.entmanagement.config;

import com.vogue.supplymall.account.shiro.filter.MallAuthenticationFilter;
import com.vogue.supplymall.account.shiro.filter.WholeAuthenticationFilter;
import com.vogue.supplymall.common.config.JacksonConvert;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * The type Order config.
 *
 * @aouthor: zhangliang
 * @date: Create in 2018-01-10
 */
@Configuration
@ComponentScan(value = {"com.vogue.supplymall.common.domain.tool",
        "com.vogue.supplymall.account.domain",
        "com.vogue.supplymall.shop.domain",
        "com.vogue.supplymall.entmanagement.domain",
        "com.vogue.supplymall.upload.domain",
        "com.vogue.supplymall.order.common",
        "com.vogue.supplymall.order.domain",
        "com.vogue.supplymall.match.domain",
        "com.vogue.supplymall.admin.business.domain.dao",
        "com.vogue.supplymall.admin.business.domain.service",
        "com.vogue.supplymall.cross.domain"
})
@ComponentScan("com.vogue.supplymall.shop.common")
@ComponentScan("com.vogue.supplymall.payment.api")
@MapperScan({"com.vogue.supplymall.account.domain.mapper",
        "com.vogue.supplymall.order.domain.mapper",
        "com.vogue.supplymall.shop.domain.mapper",
        "com.vogue.supplymall.match.domain.mapper",
        "com.vogue.supplymall.entmanagement.domain.mapper",
        "com.vogue.supplymall.admin.business.domain.mapper",
        "com.vogue.supplymall.cross.domain.mapper"})
@ImportResource(locations = {"classpath:entmanagement-context.xml", "classpath:base-context.xml"})
public class EntmanagementConfig extends WebMvcConfigurerAdapter {

    @Bean
    public FilterRegistrationBean regAuth(MallAuthenticationFilter filter) {
        FilterRegistrationBean registration = new FilterRegistrationBean(filter);
        registration.setEnabled(false);
        return registration;
    }

    @Bean
    public FilterRegistrationBean regWhole(WholeAuthenticationFilter filter) {
        FilterRegistrationBean registration = new FilterRegistrationBean(filter);
        registration.setEnabled(false);
        return registration;
    }

    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        JacksonConvert.convert(converters);
    }
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new OrderInterceptor()).addPathPatterns("/**");
//        super.addInterceptors(registry);
//    }
}
